import { Injectable } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';

@Injectable()
export class AuthorityService {
  constructor(private readonly jwtService: JwtService) {}

  public async getToken(payload) {
    return await this.jwtService.sign(payload);
  }

  async decode(stringToken) {
    if (stringToken) {
      const jwtPload = await this.jwtService.decode(stringToken);
      return jwtPload;
    }
  }

  async verify(stringToken) {
    if (stringToken) {
      return await this.jwtService.verify(stringToken);
    } else {
      return false;
    }
  }
}
